<!doctype html>
<html>
<head>
    <title>Generated test runner</title>
    <style>
        #info {
            position: absolute;
            right: 50px;
            top: 50px;
            border: 1px solid black;
            background-color: #ccc;
        }
        iframe {
            width: 650px;
            height: 85px;
            border: 1px dashed black;
        }
    </style>
</head>
<body class="yui3-skin-sam">
<h1 id="results">Calculating</h1>
<div id="info">
<p>This test will take around 6 minutes when fully run.</p>
</div>
<pre id="note"></pre>
<div id="log"></div>

<script src="/build/yui/yui.js"></script>
<script src="generated.js"></script>
<script>

//gen_tests = ['node', 'yql', 'dd', 'combo_node', 'combo_yql', 'combo_dd'];
//gen_tests = ['node', 'yql', 'dd', 'rls_node', 'rls_yql', 'rls_dd'];
//gen_tests.reverse();

var h1 = document.getElementById('results');
var note = document.getElementById('note');
var frame;
var title = 'Prepping (#) tests';
document.title = h1.innerHTML = title.replace('#', gen_tests.length);


var log = function() {
    var str = [];
    for (var i = 0; i < arguments.length; i++) {
        str.push(arguments[i]);
    }
    note.innerHTML = str.join(' ');
};

var results = {},
    Assert,
    YUITest;

var confirmTests = function() {
    document.body.removeChild(frame);
    document.title = h1.innerHTML = 'Prep Complete';
    log('Starting YUI Tests');
    var s = new YUITest.Suite("Dynamic Use");
    s.add(new YUITest.Case(cases));
    YUITest.Runner.subscribe(YUITest.Runner.COMPLETE_EVENT, function() {
        document.title = h1.innerHTML = 'Tests Complete';
        var endStamp = (new Date()).getTime();
        var str = ((endStamp - startStamp) / 1000);
        log('Tests Complete: ' + str + 'secs');
    });
    YUITest.Runner.add(s);
    YUITest.Runner.run();

};

var runTest = function() {
    var mod = gen_tests.pop();
    if (mod) {
        document.title = h1.innerHTML = title.replace('#', gen_tests.length);
        log('Fetching: ', '/tests/' + mod);
        if (!frame) {
            frame = document.createElement('iframe');
            frame.id = 'frame';
            document.body.appendChild(frame);
        }
        frame.src = '/tests/' + mod;
    } else {
        confirmTests();
    }
};

var _yui_result = function(d) {
    log('Test Completed for', d.name);
    results[d.name] = d;
    //setTimeout(function() {
        runTest();
    //}, 100);
};

var startStamp = (new Date()).getTime();

var YUI_config = {
    gconfig: true,
    gfilter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'raw'
};


YUI({
    allowRollup: false,
    logExclude: {Dom: true, Selector: true, Node: true, attribute: true, base: true, event: true, widget: true },
    filter: YUI_config.gfilter
}).use('test-console', 'test', function(Y) {
    (new Y.Test.Console()).render('#log');
    YUITest = Y.Test;
    Assert = Y.Assert;
    runTest();
});



</script>
</body>
</html>
